﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace QLNS.Models
{ 
    public class TrinhDoTinHocModels
    {

        public static List<TrinhDoTinHoc> GetDSTrinhDoTinHoc()
        {

            //khoi tao db
            ITAPMNS2013Entities context = new ITAPMNS2013Entities();

            var query = from dt in context.DSTrinhDoTinHoc
                        //where dt.IDCanBo == id
                        select dt;
            return query.ToList<TrinhDoTinHoc>();
        }

        public static List<TrinhDoTinHoc> GetTrinhDoTinHocTheoCanBo(int id)
        {

            //khoi tao db
            ITAPMNS2013Entities context = new ITAPMNS2013Entities();

            var query = from dt in context.DSTrinhDoTinHoc
                        where dt.IDCanBo == id
                        select dt;
            return query.ToList<TrinhDoTinHoc>();
        }

        public static TrinhDoTinHoc GetChiTietTrinhDoTinHoc(int id)
        {
            //khoi tao db
            ITAPMNS2013Entities context = new ITAPMNS2013Entities();
            var query = (from s in context.DSTrinhDoTinHoc
                         where s.ID == id orderby s.STT descending
                         select s).FirstOrDefault();
            return query;

        }



        public static void Add(TrinhDoTinHoc qhgd)
        {
            ITAPMNS2013Entities context = new ITAPMNS2013Entities();
            context.DSTrinhDoTinHoc.AddObject(qhgd);
            context.SaveChanges();
        }
        public static void Delete(int id)
        {
            ITAPMNS2013Entities context = new ITAPMNS2013Entities();
            var query = (from h in context.DSTrinhDoTinHoc
                         where h.ID == id
                         select h).FirstOrDefault();

            context.DSTrinhDoTinHoc.DeleteObject(query);
            context.SaveChanges();

        }
        public static void DeleteAllOfPerson(int id)
        {
            ITAPMNS2013Entities context = new ITAPMNS2013Entities();
            var query = from h in context.DSTrinhDoTinHoc
                        where h.IDCanBo == id
                        select h;
            foreach (var item in query)
            {
                context.DSTrinhDoTinHoc.DeleteObject(item);
            }
            context.SaveChanges();
        }
        //sua dan toc
        public static void Update(TrinhDoTinHoc id)
        {
            ITAPMNS2013Entities context = new ITAPMNS2013Entities();
            var query = from h in context.DSTrinhDoTinHoc
                        where h.ID == id.ID
                        select h;
            TrinhDoTinHoc kq = query.First<TrinhDoTinHoc>();
            kq = id;
            context.DSTrinhDoTinHoc.ApplyCurrentValues(kq);
            context.SaveChanges();

        }
    }
}